package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjspecification;
import com.chezhujie.www.persistence.CzjspecificationMapper;
import com.sys.core.exception.ClassCheckException;
import com.sys.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 规格参数
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjspecificationService extends BaseService<Czjspecification> {
    @Autowired
    private CzjspecificationMapper czjspecificationMapper;

    @Autowired
    public void setBaseMapper(CzjspecificationMapper czjspecificationMapper) {
        this.baseMapper = czjspecificationMapper;
    }


    public void checkEntity(Czjspecification czjspecification) throws ClassCheckException {
        if(czjspecification.getSpecificationId()!=null&&czjspecification.getSpecificationId().length()>19){
            throw new ClassCheckException("规格参数主键不能超过19个字符");
        }
        if(czjspecification.getCommodityId()!=null&&czjspecification.getCommodityId().length()>19){
            throw new ClassCheckException("规格参数商品不能超过19个字符");
        }
        if(czjspecification.getName()!=null&&czjspecification.getName().length()>19){
            throw new ClassCheckException("规格参数规格参数名称不能超过50个字符");
        }
        if(czjspecification.getValue()!=null&&czjspecification.getValue().length()>19){
            throw new ClassCheckException("规格参数规格参数内容不能超过50个字符");
        }
    }
    public void checkListEntity(List<Czjspecification> listCzjspecification) throws ClassCheckException {

        for (Czjspecification czjspecification : listCzjspecification) {
            checkEntity(czjspecification);
        }

    }


	public List<Czjspecification> getSpecByCommid(String id) {
		return czjspecificationMapper.getSpecByCommid(id);
	}
}
